/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TambahPemasok.java
 *
 * Created on 11 Feb 09, 14:00:13
 */

package com.pos.spatobiz.app.view.pemasok;

import com.pos.spatobiz.app.controller.pemasok.TambahPemasokController;
import com.pos.spatobiz.common.entity.Pemasok;
import com.pos.spatobiz.common.error.SpatoBizException;
import echo.gokil.desktop.swing.Panel;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 *
 * @author agung
 */
public class TambahPemasok extends Panel implements ApplicationContextAware, InitializingBean
{
    private static final long serialVersionUID = 1L;

    private ApplicationContext applicationContext;

    private TambahPemasokController tambahPemasokController;

    public TambahPemasokController getTambahPemasokController() {
        return tambahPemasokController;
    }

    public void setTambahPemasokController(TambahPemasokController tambahPemasokController) {
        this.tambahPemasokController = tambahPemasokController;
        buttonTambah.addActionListener(tambahPemasokController);
    }

    /** Creates new form TambahPemasok */
    public TambahPemasok() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelKode = new com.pos.spatobiz.app.view.widget.WhiteLabel();
        labelNama = new com.pos.spatobiz.app.view.widget.WhiteLabel();
        labelTelepon = new com.pos.spatobiz.app.view.widget.WhiteLabel();
        labelKontak = new com.pos.spatobiz.app.view.widget.WhiteLabel();
        labelFax = new com.pos.spatobiz.app.view.widget.WhiteLabel();
        labelEmail = new com.pos.spatobiz.app.view.widget.WhiteLabel();
        textKode = new com.pos.spatobiz.app.view.widget.TextBoxTransfer();
        textNama = new com.pos.spatobiz.app.view.widget.TextBoxTransfer();
        textTelepon = new com.pos.spatobiz.app.view.widget.TextBoxTransfer();
        textKontak = new com.pos.spatobiz.app.view.widget.TextBoxTransfer();
        textFax = new com.pos.spatobiz.app.view.widget.TextBoxTransfer();
        textEmail = new com.pos.spatobiz.app.view.widget.TextBoxTransfer();
        errorKode = new com.pos.spatobiz.app.view.widget.RedLabel();
        errorNama = new com.pos.spatobiz.app.view.widget.RedLabel();
        errorTelepon = new com.pos.spatobiz.app.view.widget.RedLabel();
        errorKontak = new com.pos.spatobiz.app.view.widget.RedLabel();
        errorFax = new com.pos.spatobiz.app.view.widget.RedLabel();
        errorEmail = new com.pos.spatobiz.app.view.widget.RedLabel();
        buttonTambah = new echo.gokil.desktop.swing.Button();
        buttonBatal = new echo.gokil.desktop.swing.Button();

        setBackground(new java.awt.Color(1, 1, 9));

        labelKode.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelKode.setText("Kode :");
        labelKode.setName("labelKode"); // NOI18N

        labelNama.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelNama.setText("Nama :");
        labelNama.setName("labelNama"); // NOI18N

        labelTelepon.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelTelepon.setText("Telepon :");
        labelTelepon.setName("labelTelepon"); // NOI18N

        labelKontak.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelKontak.setText("Kontak :");
        labelKontak.setName("labelKontak"); // NOI18N

        labelFax.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelFax.setText("Fax :");
        labelFax.setName("labelFax"); // NOI18N

        labelEmail.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelEmail.setText("Email :");
        labelEmail.setName("labelEmail"); // NOI18N

        textKode.setText("textBoxTransfer1");
        textKode.setName("textKode"); // NOI18N
        textKode.setPreferredSize(new java.awt.Dimension(120, 24));

        textNama.setText("textBoxTransfer1");
        textNama.setName("textNama"); // NOI18N
        textNama.setPreferredSize(new java.awt.Dimension(120, 24));

        textTelepon.setText("textBoxTransfer1");
        textTelepon.setName("textTelepon"); // NOI18N
        textTelepon.setPreferredSize(new java.awt.Dimension(120, 24));

        textKontak.setText("textBoxTransfer1");
        textKontak.setName("textKontak"); // NOI18N
        textKontak.setPreferredSize(new java.awt.Dimension(120, 24));

        textFax.setText("textBoxTransfer1");
        textFax.setName("textFax"); // NOI18N
        textFax.setPreferredSize(new java.awt.Dimension(120, 24));

        textEmail.setText("textBoxTransfer1");
        textEmail.setName("textEmail"); // NOI18N
        textEmail.setPreferredSize(new java.awt.Dimension(120, 24));

        errorKode.setText("error kode");
        errorKode.setName("errorKode"); // NOI18N

        errorNama.setText("error nama");
        errorNama.setName("errorNama"); // NOI18N

        errorTelepon.setText("error telepon");
        errorTelepon.setName("errorTelepon"); // NOI18N

        errorKontak.setText("error kontak");
        errorKontak.setName("errorKontak"); // NOI18N

        errorFax.setText("error fax");
        errorFax.setName("errorFax"); // NOI18N

        errorEmail.setText("error email");
        errorEmail.setName("errorEmail"); // NOI18N

        buttonTambah.setText("Tambah");
        buttonTambah.setName("buttonTambah"); // NOI18N

        buttonBatal.setText("Batal");
        buttonBatal.setName("buttonBatal"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(labelEmail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(labelFax, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(labelKontak, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(labelKode, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(labelNama, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(labelTelepon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textNama, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                            .addComponent(textTelepon, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                            .addComponent(textKontak, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                            .addComponent(textFax, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                            .addComponent(textEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                            .addComponent(textKode, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(buttonTambah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(buttonBatal, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(errorKode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorKontak, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelKode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textKode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorKode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelKontak, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textKontak, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorKontak, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(errorEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonTambah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonBatal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(96, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    public Pemasok getPemasok() throws SpatoBizException {
        boolean valid = true;
        if (textKode.getText().isEmpty())
        {
            errorKode.setText("kode tidak boleh kosong");
            valid = false;
        }
        else
        {
            errorKode.setText("");
        }
        if (textNama.getText().isEmpty()) {
            errorNama.setText("nama tidak boleh kosong");
            valid = false;
        }
        else
        {
            errorNama.setText("");
        }
        if (textTelepon.getText().isEmpty()) {
            errorTelepon.setText("Telepon tidak boleh kosong");
            valid =  false;
        }
        else
        {
            errorTelepon.setText("");
        }
        if (textKontak.getText().isEmpty()) {
            errorKontak.setText("kontak tidak boleh kosong");
            valid = false;
        }
        else
        {
            errorKontak.setText("");
        }
        if (textFax.getText().isEmpty()) {
            errorFax.setText("fax tidak boleh kosong");
            valid = false;
        }
        else
        {
            errorFax.setText("");
        }
        if (textEmail.getText().isEmpty()) {
            errorEmail.setText("email tidak boleh kosong");
            valid = false;
        }
        else
        {
            errorEmail.setText("");
        }
        if(!valid)
        {
            throw new SpatoBizException("Data tidak lengkap");
        }


        Pemasok pemasok = new Pemasok
                (
                    textKode.getText(), textNama.getText(),textTelepon.getText(),textKontak.getText(),
                    textFax.getText(),textEmail.getText()
                );
        return pemasok;
    }

    @Override
    public void onOpen() throws Exception {
        errorKode.setText("");
        errorNama.setText("");
        errorTelepon.setText("");
        errorKontak.setText("");
        errorFax.setText("");
        errorEmail.setText("");

        textKode.setText("");
        textNama.setText("");
        textTelepon.setText("");
        textKontak.setText("");
        textFax.setText("");
        textEmail.setText("");
        textKode.requestFocusInWindow();
    }




    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
        this.applicationContext = arg0;
    }

    public void afterPropertiesSet() throws Exception {

    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private echo.gokil.desktop.swing.Button buttonBatal;
    private echo.gokil.desktop.swing.Button buttonTambah;
    private com.pos.spatobiz.app.view.widget.RedLabel errorEmail;
    private com.pos.spatobiz.app.view.widget.RedLabel errorFax;
    private com.pos.spatobiz.app.view.widget.RedLabel errorKode;
    private com.pos.spatobiz.app.view.widget.RedLabel errorKontak;
    private com.pos.spatobiz.app.view.widget.RedLabel errorNama;
    private com.pos.spatobiz.app.view.widget.RedLabel errorTelepon;
    private com.pos.spatobiz.app.view.widget.WhiteLabel labelEmail;
    private com.pos.spatobiz.app.view.widget.WhiteLabel labelFax;
    private com.pos.spatobiz.app.view.widget.WhiteLabel labelKode;
    private com.pos.spatobiz.app.view.widget.WhiteLabel labelKontak;
    private com.pos.spatobiz.app.view.widget.WhiteLabel labelNama;
    private com.pos.spatobiz.app.view.widget.WhiteLabel labelTelepon;
    private com.pos.spatobiz.app.view.widget.TextBoxTransfer textEmail;
    private com.pos.spatobiz.app.view.widget.TextBoxTransfer textFax;
    private com.pos.spatobiz.app.view.widget.TextBoxTransfer textKode;
    private com.pos.spatobiz.app.view.widget.TextBoxTransfer textKontak;
    private com.pos.spatobiz.app.view.widget.TextBoxTransfer textNama;
    private com.pos.spatobiz.app.view.widget.TextBoxTransfer textTelepon;
    // End of variables declaration//GEN-END:variables

}
